<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * User Application (User), Delete User Module
 * Started: 19 September, 2009 09:14 PM
 * Script version: 1.0
 +------------------------------------
 */

class module implements module_interface{
	public function returninitvars(){
		global $lang;
		$this->info["page_title"] = $lang->getByKey("admin.user.delete");
		$this->info["page_description"] = "";
		$this->info["module_version"] = "1.0";
		return $this->info;
	}

	public function construct(){ # call our initialize functions
		if(isset($_GET['user'])){
			$this->delete = intval($_GET['user']);
		}
		else{
			$this->run = false;
		}
	}
	
	private function can_delete($data, $groupdata){
		$nodelete = array();
		$nodelete[] = "1";
		$uc = unserialize($_SESSION["cf_controller"]);
		$nodelete[] = $uc->getUID();
		// Now...
		if(in_array($data['id'], $nodelete)){
			return false;
		}
		else{
			if($groupdata->is_admin()){
				return false;
			}
			else{
				return true;
			}
		}
	}
	
	public function run(){
		global $view, $lang, $db, $models;
		$this->user = new user($this->delete);
		if($this->can_delete($this->user, $this->user->group) and $this->user->delete() === TRUE){
			$view->writeIn(
				$view->inlineSuccess(
					$lang->getByKey("admin.user.user.delete.deleted1").
					$this->delete.
					$lang->getByKey("admin.user.user.delete.deleted2")
				)
			);
		}
		else{
			$view->writeIn(
				$view->inlineError(
					$lang->getByKey("admin.user.user.delete.fail")
				)
			);
		}
	}

	public function destruct(){}
}
